<?php

include('db_connect.php');
include('session.php');
if(isset($_SESSION['user_id'])) {
  $array = array();
  
  $result = mysql_query("SELECT id FROM questions");
  while($row = mysql_fetch_array($result)) {
    if(isset($_REQUEST['button' . $row['id']]))
      $array[$row['id']] = $_REQUEST['button' . $row['id']];
    else {
      echo "WTFUUUUUUHHHHH";
      return;
    }
  }
  foreach($array as $k => $v) {
    $k = mysql_real_escape_string($k);
    $v = mysql_real_escape_string($v);
     mysql_query("INSERT INTO responses (questionid, answer, userid) VALUES ('$k', '$v','". $_SESSION['user_id']. "')");
  }
  
  echo "Great Success";
}
  else{
echo "Please Log in";
  }
?>